<?php
define("CONFIG", require '../config/config.php');
include CONFIG["app"]["util_path"] . '/debug_info.php';
include '../application/model/helper/DbModel.php';
include '../application/model/Admin.php';
include '../application/model/Department.php';
include '../application/model/Group.php';
include '../application/model/User.php';
$database = CONFIG['database'];
$db = new DbModel(
    $database['type'],
    $database['servername'],
    $database['db_name'],
    $database['username'],
    $database['password']
);
function test_admin($db)
{
    $admin = new Admin();
    $admin->setAdminId(7);
    $user = new Admin("cendeal", "123456789");
    $db->add($user);
    print_r($db->query(new Admin(), ["name" => "admin_id", "value" => "7"]));
}

function test_department($db)
{
    $dept = new Department();

    //$dept->loadData(["dept_id"=>1,"dept_info"=>3,"dept_manager_id"=>4,"dept_name"=>2]);
    //$dept->setDeptId(16);
    //$db->delete($dept);
//    if($db->query($dept,["name"=>"dept_id","value"=>1])){
//        print_r("\n[ok]".$dept."\n");
//    }
//    if ($db->edit($dept, ["dept_name"=>"test","dept_info"=>"777"])) {
//        print_r("\nfinish".$dept);
//    } else {
//        error_log($dept);
//    }
    $data= ["class"=>"Department"];
    $list = $db->list($data,1,10);
    print_r(json_encode($list));
}
function test_group($db)
{
    $gp = new Group();


    print_r($gp->getGpName());
    //$dept->setDeptId(16);
    //$db->delete($dept);
//    if($db->query($dept,["name"=>"dept_id","value"=>1])){
//        print_r("\n[ok]".$dept."\n");
//    }
//    if ($db->edit($dept, ["dept_name"=>"test","dept_info"=>"777"])) {
//        print_r("\nfinish".$dept);
//    } else {
//        error_log($dept);
//    }
    $data= ["class"=>"Group","type"=>"object"];
    $list = $db->list($data,1,10);
    print_r($list);
}
function test_user($db)
{
    $gp = new User();
    $data= ["class"=>"User"];
    $list = $db->list($data,1,10);
    print_r($list);


}
//test_user($db);
//test_department($db);
//test_group($db);
abstract class Test{
    static $name = "Test";
    static function  getName(){
        return self::$name;
    }
    function you(){
        print_r($this->getName());
    }
}

class SubTest extends Test {
    static $name = "SubTest";
    static function  getName(){
        return self::$name;
    }
}

$sub = new SubTest();
$sub->you();